//
//  HJDHomeController.m
//  JYHospital
//
//  Created by 胡金东 on 16/3/31.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDPofileControllerr.h"
#import "HJDWeightViewController.h"
#import "HJDNumberViewController.h"
#import "WaterWareView.h"
#import "MBProgressHUD.h"
#import "AFNetworking.h"
#import "MJExtension.h"
#import "HJDPodfileModel.h"
#import "BSMacros.h"


@interface HJDPofileControllerr ()<UIScrollViewDelegate>{
    int n;
    int m;
    int Days;
    int hours;
    int minute;
    int X;
    int Y;
}

@property (nonatomic,strong)NSTimer *timer;

@property (nonatomic,strong)UIScrollView *scroll;

@property (nonatomic,strong)UIScrollView *textscroll;

//@property (nonatomic,strong) UITableView * tableView;

//
@property (nonatomic,strong)  UILabel *textLbl;
@property (nonatomic,strong)  UIView *viewC;
@property (nonatomic,strong)  UIView *vC;

@property (nonatomic,strong) UILabel *twoLbl;
//背景
@property (nonatomic,strong) UIView * backgroundView;
//动画

@property (nonatomic,strong) WaterWareView *waterWareView;
//周
@property (nonatomic,strong) UILabel *timeLbl ;
//天
@property (nonatomic,strong) UILabel *timeDayLbl ;
//接收信息
@property (nonatomic,strong) NSString *sContent;
//距离预产期
@property (nonatomic,strong) UILabel *gesDayLbl ;
//宝宝头臂长
@property (nonatomic,strong) UILabel *babyHightLbl;
//宝宝体重
@property (nonatomic,strong) UILabel *babyWNumberLbl;
//末次月经
@property (nonatomic,strong)  NSString *pregnancy;
@property (nonatomic,strong) UILabel *dayLbl ;
@property (nonatomic,strong) UILabel *dateLbl ;

//图片
@property (nonatomic,strong) UIImageView *imageV;








@end

@implementation HJDPofileControllerr

-(UILabel *)timeLbl
{
    if (_timeLbl ==nil) {
        
        _timeLbl = [[UILabel alloc]init];
    }
    return _timeLbl;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //隐藏导航栏
    self.navigationController.navigationBarHidden = YES;
    
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    

    
     self.view.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
    
   //    self.model = [HJDPodfileModel new];
     NSUserDefaults *defa = [NSUserDefaults standardUserDefaults];
   self.pregnancy = [defa objectForKey:@"pregnanc"];
    
    
        NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
     [inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
     
     [inputFormatter setDateFormat:@"yyyy-MM-dd"];
     
     NSDate *inputDate = [inputFormatter dateFromString:self.pregnancy];
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    // 话说在真机上需要设置区域，才能正确获取本地日期，天朝代码:zh_CN
    dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //得到相差秒数
    NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:inputDate];
     Days = ((int)time)/(3600*24);
    hours = ((int)time)%(3600*24)/3600;
    minute = ((int)time)%(3600*24)/3600/60;
    if (Days <= 0 && hours <= 0&&minute<= 0) {
        NSLog(@"0天0小时0分钟");
      
    }
    else {
        m = Days/7;
        n = Days - m*7;
        if (n==0) {
            n = 1;
        }
        m = m+1;
            }
    
    
    X =  0;
    
    [self setUpNavi];
   
    [self setUpRequest];
   
    [self setUpBtn];

}



-(void)setUpNavi
{

    self.scroll = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.scroll.delegate = self;
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.scroll.showsVerticalScrollIndicator = NO;//垂直移动
    self.scroll.showsHorizontalScrollIndicator = NO;//水平移动
    //上下滑动
    self.scroll.contentSize = CGSizeMake(HJDWidth,620 ) ;
    [self.view addSubview: self.scroll];
//    背景
    CGFloat backH = IS_IPHONE_5?450:IS_IPHONE_6?520:IS_IPHONE_6_PLUS?590:450;
    self.backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0,HJDWidth ,backH )];
    self.backgroundView.backgroundColor = [UIColor getColorWithHexNumber:@"FFA3B0"];
    [self.scroll addSubview:self.backgroundView];
//    动画
    CGFloat waterH = IS_IPHONE_5?440:IS_IPHONE_6?570:IS_IPHONE_6_PLUS?720:440;
    CGFloat waterY = IS_IPHONE_5?10:IS_IPHONE_6?-50:IS_IPHONE_6_PLUS?-130:10;
    self.waterWareView = [[WaterWareView alloc]initWithFrame:CGRectMake(0, waterY, HJDWidth, waterH)];
    [self.backgroundView addSubview:self.waterWareView];
    
    
    CGFloat leftImgX = HJDHorizontalMargin;
    CGFloat leftImgY = HJDVerticalMargin;
    CGFloat leftImgW = 10;
    CGFloat leftImgH = 35/2;
    UIImageView *leftImg = [[UIImageView alloc]initWithFrame:CGRectMake(leftImgX, leftImgY, leftImgW, leftImgH)];
    leftImg.image = [UIImage imageNamed:@"yunBack"];
    [self.backgroundView addSubview:leftImg];
    
    CGFloat leftX = 10;
    CGFloat leftY = 10;
    CGFloat leftW = 60;
    CGFloat leftH = 55;
    UIButton *navleftBtn = [[UIButton alloc]initWithFrame:CGRectMake(leftX, leftY, leftW, leftH)];
    [navleftBtn addTarget:self action:@selector(Back) forControlEvents:UIControlEventTouchUpInside];
    [self.backgroundView addSubview:navleftBtn];
    
   
     UIView *circle = [[UIView alloc]initWithFrame:CGRectMake((HJDWidth - 188)/2, 20, 376/2, 81/2)];
    UIImage *img = [UIImage imageNamed:@"圆角矩形"];
    [circle setBackgroundColor:[UIColor colorWithPatternImage:img]];
    [self.backgroundView addSubview:circle];
    
    self.timeLbl = [[UILabel alloc]init];
     self.timeLbl.text = [NSString stringWithFormat:@"第%d周",m];
    self.timeLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:19];
    CGSize  timeLblSize = [self.timeLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeLbl.font,NSFontAttributeName ,nil]];
    self.timeLbl.textAlignment = NSTextAlignmentCenter;
    CGFloat timeLblX = (188 - timeLblSize.width)/2-20;
    CGFloat timeLblY = 10;
//    self.timeLbl.frame = (CGRect){{timeLblX,timeLblY },65,timeLblSize.height};
    self.timeLbl.frame = (CGRect){{timeLblX,timeLblY },timeLblSize};
  
    
    
    self.timeLbl.textColor = [UIColor getColorWithHexNumber:@"5CC5AC"];
   
    [circle addSubview:self.timeLbl];
    
    
    self.timeDayLbl = [[UILabel alloc]init];
    self.timeDayLbl.text = [NSString stringWithFormat:@"%d天",n];
    self.timeDayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:19];

    CGSize  timeDayLblSize = [self.timeDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeDayLbl.font,NSFontAttributeName ,nil]];
    self.timeDayLbl.textAlignment = NSTextAlignmentCenter;
    CGFloat timeDayLblX = CGRectGetMaxX(self.timeLbl.frame);
    CGFloat timeDayLblY = 10;
    self.timeDayLbl.frame = (CGRect){{timeDayLblX,timeDayLblY},timeDayLblSize};
 
    self.timeDayLbl.textColor = [UIColor getColorWithHexNumber:@"5CC5AC"];
    [circle addSubview:self.timeDayLbl];
    
    

    CGFloat leftBtnW = 34;
    CGFloat leftBtnH = 69/2;
    CGFloat leftBtnX = 1;
    CGFloat leftBtnY = 3;
    
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(leftBtnX, leftBtnY, leftBtnW, leftBtnH)];
    leftBtn.backgroundColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"孕期上"] forState:UIControlStateNormal];
    [leftBtn setRadius:leftBtnW/2 borderWith:0 borderColor:nil];
    [leftBtn addTarget:self action:@selector(upDayClick) forControlEvents:UIControlEventTouchUpInside];
    [circle addSubview:leftBtn];
    
    CGFloat rightBtnW = leftBtnW;
    CGFloat rightBtnH = leftBtnH;
    CGFloat rightBtnX = 188 - leftBtnW -1 ;
    CGFloat rightBtnY = 3;
    
    UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(rightBtnX, rightBtnY, rightBtnW, rightBtnH)];
   rightBtn.backgroundColor = [UIColor getColorWithHexNumber:@"CFCFCF"];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"孕期下"] forState:UIControlStateNormal];
  [rightBtn setRadius:leftBtnW/2 borderWith:0 borderColor:nil];
    [rightBtn addTarget:self action:@selector(nextDayClick) forControlEvents:UIControlEventTouchUpInside];
    [circle addSubview:rightBtn];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comp = [[NSDateComponents alloc]init];
    NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDate *nowDate = [NSDate date];
    comp = [calendar components:flags fromDate:nowDate];
    NSInteger month = [comp month];
    NSInteger day = [comp day];
    
    
    self.dateLbl = [[UILabel alloc]init];
    self.dateLbl.text = [NSString stringWithFormat:@"%ld.",(long)day];
    self.dateLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:24];
    CGSize  dateLblSize = [self.dateLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dateLbl.font,NSFontAttributeName ,nil]];
    CGFloat dateLblX = (HJDWidth-dateLblSize.width)/2 -10;
    CGFloat dateLblY = leftY + leftH + 31;
    //    self.dateLbl.frame = (CGRect){{dateLblX,dateLblY},35,dateLblSize.height};
    self.dateLbl.frame = (CGRect){{dateLblX,dateLblY},dateLblSize};
    
    self.dateLbl.textAlignment = NSTextAlignmentCenter;
    self.dateLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.backgroundView addSubview:self.dateLbl];


    self.dayLbl = [[UILabel alloc]init];
    self.dayLbl.text = [NSString stringWithFormat:@"%ld",(long)month];
    self.dayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    CGSize  dayLblSize = [self.dayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dayLbl.font,NSFontAttributeName ,nil]];
    CGFloat dayLblX = (HJDWidth-dayLblSize.width)/2+dateLblSize.width/2 -5  ;
    CGFloat dayLblY = leftY + leftH + HJDVerticalMargin * 2;
    self.dayLbl.frame = (CGRect){{dayLblX,dayLblY},dayLblSize};
    self.dayLbl.textAlignment = NSTextAlignmentCenter;
    self.dayLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.backgroundView addSubview:self.dayLbl];
    
   
    
//外圆
    CGFloat viewW = 150;
    CGFloat viewH = 150;
    CGFloat viewX = (HJDWidth - viewW)/2;
    CGFloat viewY = CGRectGetMaxY(self.dayLbl.frame) + HJDVerticalMargin/2;
    self.viewC = [[UIView alloc]init];
    self.viewC.frame = CGRectMake(viewX, viewY, viewW, viewH);
    self.viewC.alpha = 0.3;
    [self.viewC setRadius:viewW/2 borderWith:20 borderColor:[UIColor whiteColor]];

    [self.backgroundView addSubview:self.viewC];
//    内圆
    CGFloat vW = 110;
    CGFloat vH = 110;
    CGFloat vX = (HJDWidth - vW)/2;
    CGFloat vY = viewY + 20;
    self.vC = [[UIView alloc]init];
    self.vC.frame = CGRectMake(vX, vY, vW, vH);
    [self.vC setRadius:vW/2 borderWith:2 borderColor:[UIColor whiteColor]];
  
    [self.backgroundView addSubview:self.vC];

    self.imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, viewW, viewH)];

    if (m>=20) {
        self.imageV.image = [UIImage imageNamed:@"1"];
    }else{
    
    self.imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",m+1]];
    }

    [self.vC addSubview:self.imageV];
  
    
//    咨询
    CGFloat btnResultW = 146/2;
    CGFloat btnResultH = 64/2;
    CGFloat btnResultX = IS_IPHONE_5?CGRectGetMaxX(self.viewC.frame):IS_IPHONE_6?CGRectGetMaxX(self.viewC.frame) + HJDHorizontalMargin/2:IS_IPHONE_6_PLUS?CGRectGetMaxX(self.viewC.frame) + HJDHorizontalMargin:CGRectGetMaxX(self.viewC.frame) ;
    CGFloat btnResultY = CGRectGetMaxY(self.viewC.frame) - btnResultH ;
    UIButton *btnResult = [[UIButton alloc]initWithFrame:CGRectMake(btnResultX, btnResultY, btnResultW, btnResultH)];
    
    [btnResult addTarget:self action:@selector(resultClick) forControlEvents:UIControlEventTouchUpInside];
    [btnResult setRadius:30/2 borderWith:0 borderColor:[UIColor whiteColor]];
    btnResult.backgroundColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [btnResult setImage:[UIImage imageNamed:@"咨询"] forState:UIControlStateNormal];
    [self.backgroundView addSubview:btnResult];
    
    CGFloat LblX = 33;
    CGFloat LblY = 6;
    CGFloat LblW = 35;
    CGFloat LblH = 20;
    UILabel *Lbl = [[UILabel alloc]initWithFrame:CGRectMake(LblX, LblY, LblW, LblH)];
    Lbl.text = @"咨询";
    Lbl.font = [UIFont systemFontOfSize:15];
    Lbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    [btnResult addSubview:Lbl];

    


    CGFloat gestationLblX = HJDHorizontalMargin/2;
    CGFloat gestationLblY = IS_IPHONE_5?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 2:IS_IPHONE_6?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 8:IS_IPHONE_6_PLUS?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 15:CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 2;
    CGFloat gestationLblW = 100;
    CGFloat gestationLblH = 15;
    UILabel *gestationLbl = [[UILabel alloc]initWithFrame:CGRectMake(gestationLblX, gestationLblY, gestationLblW, gestationLblH)];
    gestationLbl.text = @"距离预产期";
    gestationLbl.font = [UIFont systemFontOfSize:15];
    gestationLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
  
    [self.waterWareView addSubview:gestationLbl];
    
    CGFloat gesDayLblX = HJDHorizontalMargin/2;
    CGFloat gesDayLblY = CGRectGetMaxY(gestationLbl.frame);

    self.gesDayLbl = [[UILabel alloc]init];
    self.gesDayLbl.text = [NSString stringWithFormat:@"%@",self.model.distancedate];
    self.gesDayLbl.font = [UIFont systemFontOfSize:30];
    CGSize  gesDayLblSize = [self.gesDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.gesDayLbl.font,NSFontAttributeName ,nil]];
    self.gesDayLbl.frame = (CGRect){{gesDayLblX,gesDayLblY},gesDayLblSize};
    self.gesDayLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.waterWareView addSubview:self.gesDayLbl];
    
    CGFloat gesDayLbllX = CGRectGetMaxX(self.gesDayLbl.frame);
    CGFloat gesDayLbllY = CGRectGetMaxY(gestationLbl.frame)+7;
    CGFloat gesDayLbllW = 30;
    CGFloat gesDayLbllH = 30;
//    CGSize  gesDayLbllSize = [self.gesDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.gesDayLbl.font,NSFontAttributeName ,nil]];
    UILabel *gesDayLbll = [[UILabel alloc]initWithFrame:CGRectMake(gesDayLbllX, gesDayLbllY, gesDayLbllW, gesDayLbllH)];
    gesDayLbll.text = @"天";
    gesDayLbll.font = [UIFont systemFontOfSize:15];
    gesDayLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.waterWareView addSubview:gesDayLbll];
    
    CGFloat babyLblX = IS_IPHONE_5?CGRectGetMaxX(gestationLbl.frame) + 10:IS_IPHONE_6?CGRectGetMaxX(gestationLbl.frame) + 30:IS_IPHONE_6_PLUS?CGRectGetMaxX(gestationLbl.frame) + 50:CGRectGetMaxX(gestationLbl.frame);
    CGFloat babyLblY = IS_IPHONE_5?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 2:IS_IPHONE_6?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 8:IS_IPHONE_6_PLUS?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 15:CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 2;
    CGFloat babyLblW = 100;
    CGFloat babyLblH = 15;
    UILabel *babyLbl = [[UILabel alloc]initWithFrame:CGRectMake(babyLblX, babyLblY, babyLblW, babyLblH)];
    babyLbl.text = @"宝宝头臂长";
    babyLbl.font = [UIFont systemFontOfSize:15];
    babyLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];

    [self.waterWareView addSubview:babyLbl];
    
    CGFloat babyHightLblX = babyLblX;
    CGFloat babyHightLblY = CGRectGetMaxY(gestationLbl.frame);
    self.babyHightLbl = [[UILabel alloc]init];
    

//    self.babyHightLbl.text = self.model.brachium;
    self.babyHightLbl.text = [NSString stringWithFormat:@"%@",self.model.brachium];
    self.babyHightLbl.font = [UIFont systemFontOfSize:30];
    self.babyHightLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    CGSize  babyHightLblSize = [self.babyHightLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.babyHightLbl.font,NSFontAttributeName ,nil]];
    self.babyHightLbl.frame = (CGRect){{babyHightLblX,babyHightLblY},babyHightLblSize};
    [self.waterWareView addSubview:self.babyHightLbl];
    
    CGFloat babyHightLbllX = CGRectGetMaxX(self.babyHightLbl.frame);
    CGFloat babyHightLbllY = babyHightLblY + 9;
    CGFloat babyHightLbllW = 30;
    CGFloat babyHightLbllH = 30;
    UILabel *babyHightLbll = [[UILabel alloc]initWithFrame:CGRectMake(babyHightLbllX, babyHightLbllY, babyHightLbllW, babyHightLbllH)];
    babyHightLbll.text = @"mm";
    babyHightLbll.font = [UIFont systemFontOfSize:15];
    babyHightLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.waterWareView addSubview:babyHightLbll];

    
    CGFloat babyWeightLblX = IS_IPHONE_5?CGRectGetMaxX(babyLbl.frame) + 10:IS_IPHONE_6?CGRectGetMaxX(babyLbl.frame) + 30:IS_IPHONE_6_PLUS?CGRectGetMaxX(babyLbl.frame) + 50:CGRectGetMaxX(babyLbl.frame);;
    CGFloat babyWeightLblY = IS_IPHONE_5?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 2:IS_IPHONE_6?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 8:IS_IPHONE_6_PLUS?CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 15:CGRectGetMaxY(self.viewC.frame)+HJDVerticalMargin * 2;
    CGFloat babyWeightLblW = 100;
    CGFloat babyWeightLblH = 15;
    UILabel *babyWeightLbl = [[UILabel alloc]initWithFrame:CGRectMake(babyWeightLblX, babyWeightLblY, babyWeightLblW, babyWeightLblH)];
    babyWeightLbl.text = @"宝宝体重";
    babyWeightLbl.font = [UIFont systemFontOfSize:15];
    babyWeightLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];

  
    [self.waterWareView addSubview:babyWeightLbl];
    
    CGFloat babyWNumberLblX = babyWeightLblX;
    CGFloat babyWNumberLblY = CGRectGetMaxY(gestationLbl.frame);
   self.babyWNumberLbl = [[UILabel alloc]init];
   
    self.babyWNumberLbl.text = [NSString stringWithFormat:@"%@",self.model.weight];
    self.babyWNumberLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
     self.babyWNumberLbl.font = [UIFont systemFontOfSize:30];
    CGSize  babyWNumberLblSize = [self.babyWNumberLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.babyWNumberLbl.font,NSFontAttributeName ,nil]];
    self.babyWNumberLbl.frame = (CGRect){{babyWNumberLblX,babyWNumberLblY},babyWNumberLblSize.width +8,babyWNumberLblSize.height};
   
    [self.waterWareView addSubview:self.babyWNumberLbl];
    
    CGFloat babyWNumberLbllX = CGRectGetMaxX(self.babyWNumberLbl.frame)-5;
    CGFloat babyWNumberLbllY = CGRectGetMaxY(gestationLbl.frame) +7;
    CGFloat babyWNumberLbllW = 30;
    CGFloat babyWNumberLbllH = 30;
    UILabel *babyWNumberLbll = [[UILabel alloc]initWithFrame:CGRectMake(babyWNumberLbllX, babyWNumberLbllY, babyWNumberLbllW, babyWNumberLbllH)];
    babyWNumberLbll.text = @"g";
    babyWNumberLbll.font = [UIFont systemFontOfSize:15];
    babyWNumberLbll.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
    [self.waterWareView addSubview:babyWNumberLbll];
    
    self.textscroll = [[UIScrollView alloc]initWithFrame:CGRectMake(10,CGRectGetMaxY(self.babyWNumberLbl.frame) + HJDVerticalMargin/2,HJDWidth - HJDHorizontalMargin  , 70)];
    self.textscroll.delegate = self;
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.textscroll.showsVerticalScrollIndicator = YES;//垂直移动
    self.textscroll.showsHorizontalScrollIndicator = NO;//水平移动
    
    
    [self.waterWareView addSubview:self.textscroll];
    
//    //        文字说明
    self.textLbl = [[UILabel alloc]init];
//
//    self.textLbl.numberOfLines = 0;
//
//        self.textLbl.text = [NSString stringWithFormat:@"%@",self.model.content];
//    self.textLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
//    self.textLbl.font = [UIFont systemFontOfSize: 15];
//    
//    CGRect textLblRect = [_textLbl.text boundingRectWithSize:CGSizeMake(textLblW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.textLbl.font,NSFontAttributeName, nil] context:nil];
//    self.textLbl.frame = (CGRect){{textLblX,textLblY},textLblRect.size};
//    
//    
//    [self.textscroll addSubview:self.textLbl];
    


//    //上下滑动
//    self.textscroll.contentSize = CGSizeMake(HJDWidth - HJDHorizontalMargin *2,200) ;
    

}


-(void)setUpRequest{
    
    NSUserDefaults *defat = [NSUserDefaults standardUserDefaults];
    NSString *phone = [defat objectForKey:@"phonenum"];
    
    NSString *url = @"/app/task.do";
    NSString *path = [Hurl stringByAppendingString:url];
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"phone"] = phone;
    params[@"pregnancy"] = self.pregnancy;
   
    
    [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
      
        NSDictionary *dic =(NSDictionary *)responseObject;
        NSString *resultMap = dic[@"resultMap"];

        if (![resultMap isEqual:[NSNull null]]) {
            
            
            self.model =  [HJDPodfileModel mj_objectWithKeyValues:resultMap];
            self.timeLbl.text = [NSString stringWithFormat:@"第%d周",m];
            CGSize  timeLblSize = [self.timeLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeLbl.font,NSFontAttributeName ,nil]];
            CGFloat timeLblX = (188 - timeLblSize.width)/2-15;
           
            self.timeLbl.frame = (CGRect){{timeLblX,10 },timeLblSize};
            self.timeDayLbl.text = [NSString stringWithFormat:@"%d天",n];
            CGSize  timeDayLblSize = [self.timeDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeDayLbl.font,NSFontAttributeName ,nil]];
          
            CGFloat timeDayLblX = CGRectGetMaxX(self.timeLbl.frame);
            CGFloat timeDayLblY = 10;
            self.timeDayLbl.frame = (CGRect){{timeDayLblX,timeDayLblY},timeDayLblSize};
            self.gesDayLbl.text = [NSString stringWithFormat:@"%@",self.model.distancedate];

            self.babyWNumberLbl.text = [NSString stringWithFormat:@"%@",self.model.weight];
            self.babyHightLbl.text = [NSString stringWithFormat:@"%@",self.model.brachium];
            CGFloat textLblX = 0;
            CGFloat textLblY = 0;
            CGFloat textLblW = HJDWidth - HJDHorizontalMargin *2;
            self.textLbl.numberOfLines = 0;
            
            self.textLbl.text = [NSString stringWithFormat:@"%@",self.model.content];
            self.textLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
            self.textLbl.font = [UIFont systemFontOfSize: 15];
            
            CGRect textLblRect = [_textLbl.text boundingRectWithSize:CGSizeMake(textLblW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.textLbl.font,NSFontAttributeName, nil] context:nil];
            self.textLbl.frame = (CGRect){{textLblX,textLblY},textLblRect.size};
            
            
            [self.textscroll addSubview:self.textLbl];
            
            //上下滑动
            self.textscroll.contentSize = CGSizeMake(HJDWidth - HJDHorizontalMargin *2,textLblRect.size.height) ;

        }else{
        
            self.timeLbl.text = [NSString stringWithFormat:@"第%d周",m];
            CGSize  timeLblSize = [self.timeLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeLbl.font,NSFontAttributeName ,nil]];
            CGFloat timeLblX = (188 - timeLblSize.width)/2-15;
            self.timeLbl.frame = (CGRect){{timeLblX,10 },timeLblSize};

            self.timeDayLbl.text = [NSString stringWithFormat:@"%d天",n];
            CGSize  timeDayLblSize = [self.timeDayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.timeDayLbl.font,NSFontAttributeName ,nil]];
            
            CGFloat timeDayLblX = CGRectGetMaxX(self.timeLbl.frame);
            CGFloat timeDayLblY = 10;
            self.timeDayLbl.frame = (CGRect){{timeDayLblX,timeDayLblY},timeDayLblSize};

            self.gesDayLbl.text = @"0";
            self.babyWNumberLbl.text = @"0";
            self.babyHightLbl.text =@"0";
            CGFloat textLblX = 0;
            CGFloat textLblY = 0;
            CGFloat textLblW = HJDWidth - HJDHorizontalMargin ;
            self.textLbl.numberOfLines = 0;
            self.textLbl.text = @"现在你正在排卵期，基础体温有变化吗？如果受精卵已经形成，虽然你不会有什么感觉，但是，你已经迈出女人一生中最重要的一步，开始成为完美与成熟的女性。想想吧，一个天使一般可爱的孩子，他全心依赖你，叫你“妈妈”。这怎能不令人心神向往。让我们期待吧！";
            
            self.textLbl.textColor = [UIColor getColorWithHexNumber:@"FFFFFD"];
            self.textLbl.font = [UIFont systemFontOfSize: 15];
            
            CGRect textLblRect = [_textLbl.text boundingRectWithSize:CGSizeMake(textLblW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.textLbl.font,NSFontAttributeName, nil] context:nil];
            self.textLbl.frame = (CGRect){{textLblX,textLblY},textLblRect.size};
            
            
            [self.textscroll addSubview:self.textLbl];
            //上下滑动
            self.textscroll.contentSize = CGSizeMake(HJDWidth - HJDHorizontalMargin *2,textLblRect.size.height) ;

        }


    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [MBProgressHUD showError:@"服务器升级，请稍后再试"];

    }];
    
}

//按钮
-(void)setUpBtn
{
    
   UIView *viewM = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.backgroundView.frame) , HJDWidth , 130)];
    viewM.backgroundColor = [UIColor whiteColor];
    [self.scroll addSubview:viewM];
    
//        CGFloat viewMagrinX = HJDWidth/2;
//        CGFloat viewMagrinY = HJDVerticalMargin + 10 ;
//        CGFloat viewMagrinW = 1;
//        CGFloat viewMagrinH =  70;
//        UIView *viewMarin = [[UIView alloc]initWithFrame:CGRectMake(viewMagrinX, viewMagrinY, viewMagrinW, viewMagrinH)];
//        viewMarin.backgroundColor = [UIColor getColorWithHexNumber:@"F1F1EE"];
//        [viewM addSubview:viewMarin];


//    CGFloat btnOneX = 50;
//    CGFloat btnOneY =  HJDVerticalMargin ;
//    CGFloat btnOneW = 122/2;
//    CGFloat btnOneH = 134/2;
//    UIButton *btnOne = [[UIButton alloc]initWithFrame:CGRectMake(btnOneX, btnOneY, btnOneW, btnOneH)];
////    [btnOne setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
//    [btnOne setBackgroundImage:[UIImage imageNamed:@"数胎动"] forState:UIControlStateNormal];
//    [btnOne addTarget:self action:@selector(oneClick) forControlEvents:UIControlEventTouchUpInside];
//
//    [viewM addSubview:btnOne];
//    
//    
//    UILabel *oneLbl = [[UILabel alloc]init];
//    oneLbl.text = @"数胎动";
//    oneLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
//    CGSize  oneLblSize = [oneLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:oneLbl.font,NSFontAttributeName ,nil]];
//    CGFloat oneLblX = btnOneX + btnOneW/2 -oneLblSize.width/2;
//    CGFloat oneLblY = CGRectGetMaxY(btnOne.frame) +HJDVerticalMargin/2 ;
//    oneLbl.frame = (CGRect){{oneLblX,oneLblY},oneLblSize};
////    oneLbl.textAlignment = NSTextAlignmentCenter;
//    oneLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
//    [viewM addSubview:oneLbl];
    
    
    CGFloat btnTwoX = (HJDWidth - 61)/2;
    CGFloat btnTwoY = HJDVerticalMargin + 7;
    CGFloat btnTwoW = 61;
    CGFloat btnTwoH = 61;
    UIButton *btnTwo = [[UIButton alloc]initWithFrame:CGRectMake(btnTwoX, btnTwoY, btnTwoW, btnTwoH)];
//    [btnTwo setBackgroundColor:[UIColor getColorWithHexNumber:@"FE93A2"]];
    [btnTwo addTarget:self action:@selector(twoClick) forControlEvents:UIControlEventTouchUpInside];
    [btnTwo setBackgroundImage:[UIImage imageNamed:@"体重"] forState:UIControlStateNormal];
    [btnTwo setRadius:btnTwoW/2 borderWith:0 borderColor:nil];
    [viewM addSubview:btnTwo];
    
    
    self.twoLbl = [[UILabel alloc]init];
    self.twoLbl.text = @"称重";
    self.twoLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
    CGSize  twoLblSize = [_twoLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.twoLbl.font,NSFontAttributeName ,nil]];
    CGFloat twoLblX = btnTwoX + btnTwoW/2 - twoLblSize.width/2 ;
    CGFloat twoLblY = CGRectGetMaxY(btnTwo.frame) +HJDVerticalMargin/2 ;
    self.twoLbl.frame = (CGRect){{twoLblX,twoLblY},twoLblSize};
    //    oneLbl.textAlignment = NSTextAlignmentCenter;
    self.twoLbl.textColor = [UIColor getColorWithHexNumber:@"848484"];
    [viewM addSubview:self.twoLbl];
    
    


}

//-(void)oneClick
//{
//    HJDNumberViewController *number = [[HJDNumberViewController alloc]init];
//    [self.navigationController pushViewController:number animated:YES];
//}

-(void)twoClick
{
    HJDWeightViewController *weight = [[HJDWeightViewController alloc]init];
//    [self presentViewController:weight animated:YES completion:nil];
    
    [self.navigationController pushViewController:weight animated:YES];
}

-(void)resultClick
{
    // 检测是否安装了QQ
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"mqq://"]]) {
        
        NSUserDefaults *qqkf = [NSUserDefaults standardUserDefaults];
        NSString *qqKF = [qqkf objectForKey:@"qqKF"];
        if (qqKF != nil) {
            UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
            NSString *string = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",qqKF];
            [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
            [self.view addSubview:webView];
            NSLog(@"你安装了qq");
            
        }else{
                
        NSString * url = @"/app/kefu.do";
        NSString *path = [Hurl stringByAppendingString:url];
        AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [mgr POST:path parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSDictionary *info = (NSDictionary *)responseObject;
            NSString *success = info[@"resultCode"];
            NSString *strqq = info[@"resultMap"];
            NSUserDefaults *defa = [NSUserDefaults standardUserDefaults];
            [defa setObject:strqq forKey:@"qqKF"];
            if ([success integerValue]==0) {
                UIWebView * webView = [[UIWebView alloc] initWithFrame:CGRectZero];
                NSString *string = [NSString stringWithFormat:@"mqq://im/chat?chat_type=wpa&uin=%@&version=1&src_type=web",strqq];
                [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:string]]];
                [self.view addSubview:webView];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"error%@",error);
        }];
        }
    }else{
        [MBProgressHUD  showError:@"你还没有安装QQ,请安装QQ"];
//        NSLog(@"没有安装");
    }

}


-(void)upDayClick
{

    X-=1;
    

    if (n-1 ==0 &&m-1 ==0) {
        n = m = 1;
        [MBProgressHUD showError:@"超了你设置的预产期了"];
    }else{
    if (n-1 <=0) {
        n = 7;
        if (m-1 <=0) {
            m=1;
        }else{
            m-=1;
        }
    
    }else{
        n -= 1;
           }
        
        NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
        [inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
        NSTimeInterval  oneDay = 24*60*60;
        
        [inputFormatter setDateFormat:@"yyyy-MM-dd"];
        
        NSDate *inputDate = [inputFormatter dateFromString:self.pregnancy];
        
        NSDate *nextDate = [NSDate dateWithTimeInterval:oneDay sinceDate:inputDate];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *strDate = [dateFormatter stringFromDate:nextDate];
        self.pregnancy = strDate;
//        NSLog(@"%@-------%@----",strDate,self.pregnancy);
        
        if (m>=20) {
            self.imageV.image = [UIImage imageNamed:@"1"];
        }else{
            
            self.imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",m+1]];
        }
        
        
//        self.imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",m+1]];
NSLog(@"-----%d",m);
        
        [self dianji:m Day:n Shu:X];

    }
    
    NSLog(@"上一天");
}

-(void)nextDayClick
{
    X+=1;
    
    
    
    
    if (m>=41) {
        [MBProgressHUD showError:@"宝宝已出生了，好好照顾"];
    }else{
    if (m+1 == 41&&n+1==8) {
        m= 40;
        n= 7;
        [MBProgressHUD showError:@"宝宝已出生了，好好照顾"];

    }else{
    if (n+1 >=8) {
        n = 1;
        if (m +1 >41) {
            m= 40;
        }else{
            m +=1;
        }
      
    }else{
        n +=1;
    }
    
        
        NSDateFormatter *inputFormatter = [[NSDateFormatter alloc] init];
        [inputFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
        NSTimeInterval  oneDay = 24*60*60;
        
        [inputFormatter setDateFormat:@"yyyy-MM-dd"];
        
        NSDate *inputDate = [inputFormatter dateFromString:self.pregnancy];
        
        NSDate *nextDate = [NSDate dateWithTimeInterval:-oneDay sinceDate:inputDate];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSString *strDate = [dateFormatter stringFromDate:nextDate];
        self.pregnancy = strDate;
        NSLog(@"%@-------%@----",strDate,self.pregnancy);
        
        
        
        if (m>=20) {
            self.imageV.image = [UIImage imageNamed:@"1"];
        }else{
            
            self.imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",m+1]];
        }
        
//        self.imageV.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",m+1]];

        NSLog(@"-----%d",m);
        [self dianji:m Day:n Shu:X];
        

}

}
    
    NSLog(@"下一天");
}

-(void)dianji:(NSInteger)week Day:(NSInteger)day Shu:(int)shu{
    
    NSTimeInterval  oneDay = 24*60*60;
    NSDate *UpDate = [NSDate dateWithTimeInterval:oneDay*shu sinceDate:[NSDate date]];
    NSLog(@"update------%@",UpDate);
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSDateComponents *comp = [[NSDateComponents alloc]init];
    NSInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday |
    NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    comp = [calendar components:flags fromDate:UpDate];
    NSInteger month = [comp month];
    NSInteger days = [comp day];
    
    self.dateLbl.text = [NSString stringWithFormat:@"%ld.",(long)days];
    self.dateLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:24];
    CGSize  dateLblSize = [self.dateLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dateLbl.font,NSFontAttributeName ,nil]];
    CGFloat dateLblX = (HJDWidth-dateLblSize.width)/2-10 ;
    CGFloat dateLblY = 35/2 + 20 + 31;
    self.dateLbl.frame = (CGRect){{dateLblX,dateLblY},dateLblSize};

    
    self.dayLbl.text = [NSString stringWithFormat:@"%ld",(long)month];
    self.dayLbl.font = [UIFont fontWithName:@"HelveticaNeue" size:15];
    CGSize  dayLblSize = [self.dayLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:self.dayLbl.font,NSFontAttributeName ,nil]];
    CGFloat dayLblX = (HJDWidth-dayLblSize.width)/2+dateLblSize.width/2 -5;
    CGFloat dayLblY = 20 + 35/2 + HJDVerticalMargin * 2;
    self.dayLbl.frame = (CGRect){{dayLblX,dayLblY},dayLblSize};
    
    
   
   
    
    [self setUpRequest];
}

-(void)Back
{
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end
